<?php

namespace App\Http\Controllers\Api\V1;

use App\Models\GoldSubsidy;

class GoldSubsidiesController extends Controller
{
	public function index()
	{
		$user = request()->user();
		$condition = request('condition');
		$query = GoldSubsidy::query();
		if($condition){

			$query->where("remark",$condition);
		}
		$query = $query->where('user_id', $user->id);
		$query = !empty(request('start_time')) ? $query->where('created_at', '>', request('start_time')) : $query;
		$query = !empty(request('end_time')) ? $query->where('created_at', '<', request('end_time')) : $query;

		
		$total = $query->sum('money');
		$coins = $query->orderByDesc('id')->paginate();
		
		return ['total' => $total, 'data' => $coins];
	}
}
